<?php include("../config.php"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title><?php echo $sitename; ?> - Sysop: Add/Modify Affiliate/Spotlight Data</title>
<meta name="description" content="<?php echo $sitename; ?> - Sysop: Add/Modify Affiliate Data">
<meta name="keywords" content="free to try, software, shareware, freeware, developers, vendors, download, PAD">
<meta name="author" content="Andrey Aleksanyants, M.D.">
<meta name="copyright" content="easy HTools">
<meta http-equiv="imagetoolbar" content="no">
<link rel="stylesheet" type="text/css" href="../<?php echo $cssfile; ?>">
<link rel="shortcut icon" href="../favicon.ico">
<script language="javascript">
<!--
function formcheck() {
	if(document.aflmodify.progid.value=="") {
		alert("You did not specify Program ID!");
		document.aflmodify.progid.focus();
		return false;
	}
	if(document.aflmodify.affiliate.selectedIndex == 0) {
		alert("You did not select Affiliate Program!");
		document.aflmodify.affiliate.focus();
		return false;
	}
	if(document.aflmodify.affiliateid.value=="") {
		alert("You did not specify Affiliate ID!");
		document.aflmodify.affiliateid.focus();
		return false;
	}
	return true;
}
//-->
</script>
</head>
<body>
<table class="tmain" align="center" width="90%" cellspacing="0" cellpadding="0">
<tr>
<td class="tmain">
<table class="tlogo" align="center" width="100%" cellspacing="0" cellpadding="4">
<tr>
<td align="right">
<p><a href="index.php">Home</a></p>
</td>
</tr>
</table>
</td>
</tr><tr>
<td class="tmain">
<br>
<table align="center" width="100%" border="0" cellspacing="0" cellpadding="1">
<tr valign="top">
<td class="tbody">
<h1><?php echo $sitename; ?> - Sysop: Add/Modify Affiliate/Spotlight Data</h1>
<?php

// Requesting form data
$progid      = intval($_POST["progid"]);
$affiliate   = $_POST["affiliate"];
$affiliateid = $_POST["affiliateid"];
$submit      = $_POST["submit"];
$spotlight	 = $_POST["spotlight"];
$discounturl = $_POST["discounturl"];

if(empty($submit)) {
	$progid      = $_GET["progid"];
	$affiliate   = $_GET["affiliate"];
	$affiliateid = $_GET["affiliateid"];
	$spotlight	 = $_GET["spotlight"];
	$discounturl = $_GET["discounturl"];
	if($spotlight==1){
		$spotcheck="selected";
	}
	if($affiliate) {
		if($affiliate == "RegNow")           $chkregnow = "selected";
		if($affiliate == "Share-It")         $chkshareit = "selected";
		if($affiliate == "eSellerate")       $chkesellerate = "selected";
		if($affiliate == "Plimus")           $chkplimus = "selected";
	}

	echo "<form name=\"aflmodify\" action=\"" . $PHP_SELF . "\" method=\"post\" onsubmit=\"return formcheck()\">\n";
	echo "<table class=\"tvisible\" align=\"center\" width=\"440\" cellspacing=\"0\" cellpadding=\"4\">\n";
	echo "<tr>\n";
	echo "<th class=\"tablehead\" colspan=\"2\">Add/Modify Affiliate Data</th>\n";
	echo "</tr><tr>\n";
	echo "<td class=\"tdark\"><label for=\"progid\"><p><b>Program ID:</b></p></label></td>\n";
	echo "<td><input type=\"text\" class=\"text\" name=\"progid\" size=\"10\" maxlength=\"10\" value=\"" . $progid . "\"></td>\n";
	echo "</tr><tr>\n";
	echo "<td class=\"tdark\"><label for=\"affiliate\"><p><b>Affiliate Program:</b></p></label></td>\n";
	echo "<td><select name=\"affiliate\" id=\"affiliate\" size=\"1\">\n";
	echo "<option>&lt; Select &gt; &nbsp; &nbsp;</option>\n";
	echo "<option value=\"RegNow\" " . $chkregnow . ">RegNow</option>\n";
	echo "<option value=\"Share-It\" " . $chkshareit . ">Share-It</option>\n";
	echo "<option value=\"eSellerate\" " . $chkesellerate . ">eSellerate</option>\n";
	echo "<option value=\"Plimus\" " . $chkplimus . ">Plimus</option>\n";
	echo "</select><select name=\"spotlight\"><option value=\"0\" $spotcheck>NO</option><option value=\"1\" $spotcheck>yes</option></select> &nbsp; Product ID:\n";
	echo "<input type=\"text\" class=\"text\" name=\"affiliateid\" id=\"affiliateid\" size=\"8\" maxlength=\"16\" value=\"" . $affiliateid . "\"></td>\n";
	echo "</tr><tr>\n";
	echo "<td class=\"tdark\"><label for=\"progid\"><p><b>Discount URL:</b></p></label></td>\n";
	echo "<td><input type=\"text\" class=\"text\" name=\"discounturl\" size=\"50\" maxlength=\"100\" value=\"" . $discounturl . "\"></td>\n";
	echo "</tr><tr>\n";
	echo "<td class=\"tdark\"><p><b>Submit:</b></p></td>\n";
	echo "<td><input type=\"submit\" class=\"button\" name=\"submit\" value=\"  Submit  \"></td>\n";
	echo "</tr>\n";
	echo "</table>\n";
	echo "</form><br>\n";
}
else {
	$bad = "";
	if(empty($progid))      $bad.= "You did not specify Program ID!<br>\n";
	if(empty($affiliate))   $bad.= "You did not select Affiliate Program!<br>\n";
	if(empty($affiliateid)) $bad.= "You did not specify Affiliate ID!<br>\n";
	if($bad) {
		echo "<h2 class=\"red\">" . $bad . "</h2>";
		echo "<p>Go <a href=\"javascript:history.back()\">Back</a> and fill the form correctly.</p>\n";
		exit;
	}
	
	// Connecting to database
	if(!($link_id = mysql_connect($dbhost, $userid, $userpassword))) {
		die("<p><b>Error connecting to the database server:</b> " . mysql_error() . "</p>\n");
	}
	mysql_select_db($dbname);
	mysql_query("UPDATE paddata SET affiliate = '$affiliate', discounturl = '$discounturl',affiliateid = '$affiliateid',spotlight=$spotlight WHERE progid = '$progid'", $link_id) or die("<p>Error adding Affiliate Data: " . mysql_error() . "</p>\n");
	echo "<p>Affiliate Data successfully added. View details <a href=\"/details.php?progid=" . $progid . "\">here</a>.</p>\n";
	echo "<p>Go <a href=\"javascript:history.back()\">Back</a> to add/modify Affiliate Data for another software.</p>\n";
	echo "<p><a href=\"aflmanage.php\">Manage</a> your Affiliate Data.</p>\n";
	
	// Disconnecting from database
	mysql_close($link_id);
}
?>
<br>

</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>